package com.sample.ab;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
/**
 * @author 张智研
 * @date 2025/02/17 15:33
 **/
public class PDFToTIFF {
    public static void main(String[] args) {
        try (PDDocument document = Loader.loadPDF(new File("/Users/zhangzhiyan/Downloads/DM023566219.pdf"))) {
            PDFRenderer renderer = new PDFRenderer(document);
            BufferedImage image = renderer.renderImage(0, 1.5f); // 渲染第一页，缩放因子为1.5f
            File outputFile = new File("/Users/zhangzhiyan/Downloads/DM023566219.tiff");
            ImageIO.write(image, "TIFF", outputFile); // 保存为TIFF格式
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}